package control.servlet.authentification;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import control.bd.requete.Requetes;


public class AuthentificationServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException{
		
		String login = request.getParameter("login");
		String mdp = request.getParameter("password");
		HttpSession session = request.getSession();
		session.setAttribute("login", login);
		session.setAttribute("password", mdp);
	
	
		boolean ok = Requetes.connexion(login,mdp);
		 if(ok == true){
			   request.getRequestDispatcher("/fin.html").forward(request, response);
		   }else{
			   request.getRequestDispatcher("/Authentification/connexion.html").forward(request, response); 
		   } 
		 
			/*	Connection connexion = Connexion.getConnexionBD();
			
			ResultSet resultats = null; */
		 
	/*	String requete = "SELECT PASSWORD FROM utilisateur WHERE LOGIN = '"+login+"'";
		try {
		   Statement stmt = connexion.createStatement();
		   resultats = stmt.executeQuery(requete);
		   String mdpBD = null;
		   
		   while (resultats.next()) {
			   mdpBD = resultats.getString(1);
		   }
		   
		   if(mdpBD != null && mdp.equals(mdpBD)){
			   request.getRequestDispatcher("/fin.html").forward(request, response);
		   }else{
			   request.getRequestDispatcher("Authentification/connexion.html").forward(request, response); 
		   } 
		   
		} catch (SQLException e) {
		   //traitement de l'exception
		} */
		
		//request.getRequestDispatcher("accueil.jsp").forward(request, response);
	}	 

}
